<%@ page import="com.xju.entity.User" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的信息</title>
    <link rel="stylesheet" type="text/css" href="static/css/style.css">
    <style>
        .user-info {
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
            background-color: #f9f9f9;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .user-info h2 {
            text-align: center;
            margin-bottom: 20px;
        }

        .user-info form {
            display: flex;
            flex-direction: column;
        }

        .user-info label {
            margin-bottom: 5px;
            font-weight: bold;
        }

        .user-info input[type="text"],
        .user-info input[type="email"] {
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        .user-info .button-container {
            display: flex;
            justify-content: center;
            margin-top: 15px;
        }

        .user-info input[type="submit"],
        .user-info input[type="button"] {
            padding: 10px 20px;
            margin: 0 10px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100px; /* 设置按钮宽度 */
        }

        .user-info input[type="submit"] {
            background-color: #28a745;
            color: white;
        }

        .user-info input[type="submit"]:hover {
            background-color: #218838;
        }

        .user-info input[type="button"] {
            background-color: #007bff;
            color: white;
        }

        .user-info input[type="button"]:hover {
            background-color: #0056b3;
        }

        .message {
            text-align: center;
            margin-bottom: 20px;
        }

        .message.success {
            color: green;
        }

        .message.error {
            color: red;
        }
    </style>
</head>
<body>
<header>
    <h1>电子商务系统 - 我的信息</h1>
    <nav>
        <ul>
            <li><a href="index.jsp">首页</a></li>
            <li><a href="products.jsp">产品列表</a></li>
            <li><a href="cart.jsp">购物车</a></li>
            <li>
                <div class="user-profile">
                    <img src="static/images/user.png" alt="User Profile" class="profile-img">
                    <div class="user-menu">
                        <a href="myinfo.jsp">我的信息</a>
                        <a href="logout.jsp">退出登录</a>
                        <a href="orders.jsp">我的订单</a>
                    </div>
                </div>
            </li>
        </ul>
    </nav>
</header>
<main>
    <section class="user-info">
        <h2>个人信息</h2>
        <%
            String updateMessage = (String) session.getAttribute("updateMessage");
            if (updateMessage != null) {
        %>
        <div class="message success"><%= updateMessage %></div>
        <%
                session.removeAttribute("updateMessage");
            }
        %>
        <%
            String errorMessage = (String) request.getAttribute("errorMessage");
            if (errorMessage != null) {
        %>
        <div class="message error"><%= errorMessage %></div>
        <%
            }
        %>
        <%
            User user = (User) session.getAttribute("user");
            if (user == null) {
                response.sendRedirect("login.jsp");
            } else {
        %>
        <form action="UpdateUserInfoServlet" method="post">
            <label for="username">用户名:</label>
            <input type="text" id="username" name="username" value="<%= user.getUsername() %>" required><br><br>
            <label for="email">邮箱:</label>
            <input type="email" id="email" name="email" value="<%= user.getEmail() %>" required><br><br>
            <div class="button-container">
                <input type="submit" value="保存更改">
                <input type="button" value="返回" onclick="window.location.href='index.jsp'">
            </div>
        </form>
        <%
            }
        %>
    </section>
</main>
<footer>
    <p>&copy; 2023 电子商务系统. All rights reserved.</p>
</footer>
<script src="static/js/main.js"></script>
</body>
</html>
